package com.bnz.controller;

import com.bnz.entity.Student;
import com.bnz.service.StudentService;
import com.bnz.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/query")
public class QureyOne extends HttpServlet {

    private StudentService studentService;


    public void init() throws ServletException {

        studentService = new StudentServiceImpl();
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        req.setCharacterEncoding("utf-8");
        queryOne(req , resp);


    }
    public void queryOne(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String id = req.getParameter("id");

        Student student = studentService.queryById(Integer.valueOf(id));
        System.out.println(student);
        req.setAttribute("student",student);

        req.getRequestDispatcher("/WEB-INF/jsp/student/modify.jsp").forward(req,resp);
    }
}
